<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;

/**
 * Class ShareFreeOrder
 * 
 * @property int $id
 * @property int $share_id
 * @property int $goods_id
 * @property string $goods_name
 * @property string $goods_image
 * @property string $amount
 * @property int $uid
 * @property int|null $status
 * @property int|null $numbers
 * @property int|null $now_numbers
 * @property Carbon|null $end_time
 * @property Carbon|null $create_at
 * @property Carbon|null $update_at
 *
 * @package App\Models
 */
class ShareFreeOrder extends BaseModels
{
	protected $table = 'zh_share_free_order';


	const WAIT = 0; //筹备中

    const SUCCESS = 1; //已完成

    const FAILED = -1; //订单作废

    const SUBMIT = 2; //已成单

	protected $dates = [
		'end_time',
		'create_at',
		'update_at'
	];

	protected $appends = [
	    'status_string', 'user'
    ];

	protected $fillable = [
		'share_id',
        'goods_id',
        'goods_name',
        'goods_image',
        'amount',
		'uid',
		'status',
		'numbers',
		'now_numbers',
		'end_time',
		'create_at',
		'update_at'
	];


	public function getStatusStringAttribute()
    {
        switch ($this->status){
            case self::WAIT:
                return '筹备中';
            case self::SUCCESS:
                return '筹备完成';
            case self::FAILED:
                return '订单作废';
            case self:: SUBMIT:
                return '已成单';
            default:
                return '';
        }
    }


    public function getUserAttribute()
    {
        return User::find($this->uid);
    }
}
